//:C07:StringDeque.cpp
// Converted from StringVector.cpp.
#include <bits/types/clock_t.h>
#include <cstddef>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>
#include "../require.h"
using namespace std;

int main(int argc, char* argv[])
{
    char* fname = "StringDeque.cpp";
    if(argc > 1)
    {
        fname = argv[1];
    }
    ifstream in(fname);
    assure(in, fname);
    vector<string> vstrings;
    deque<string> dstrings;
    string line;
    // Time reading into vector;
    clock_t ticks = clock();
    while(getline(in, line))
    {
        vstrings.push_back(line);
    }
    ticks = clock() - ticks;

    cout << "Read into vector: " << ticks << endl;
    // Repeat for deque:
    ifstream in2(fname);
    assure(in2, fname);
    ticks = clock();
    while(getline(in2, line))
    {
        dstrings.push_back(line);
    }
    ticks = clock() - ticks;
    cout << "Read into deque: " << ticks << endl;
    // Now compare indexing:
    ticks = clock();
    for(size_t i = 0; i < vstrings.size(); i++)
    {
        ostringstream ss;
        ss << i;
        vstrings[i] = ss.str() + ": " + vstrings[i];
    }
    ticks = clock() - ticks;
    cout << "Indexing vector: " << ticks << endl;
    ticks = clock();
    for(size_t j = 0; j < dstrings.size(); j++)
    {
        ostringstream ss;
         ss << j;
         dstrings[j] = ss.str() + ": " + dstrings[j];
    }
    ticks = clock() - ticks;
    cout << "Indexing deque: " << ticks << endl;
    // Compare iteration
    ofstream tmpl("tmpl.tmp"), tmp2("tmp2.tmp");
    ticks = clock();
    copy(vstrings.begin(), vstrings.end(),
        ostream_iterator<string>(tmp1, "\n"));
    ticks = clock() - ticks;
    cout << "Iterating vector: " << ticks << endl;
    ticks = clock();

    copy(dstrings.begin(), dstrings.end(),
        ostream_iterator<string>(tmp2, "\n")); 
    ticks = clock() - ticks;       
    cout << "Iteraing deque: " << ticks << endl;
}